package cn.lystudio.rohmtimeopwide_background_v11.service.impl;

import cn.lystudio.rohmtimeopwide_background_v11.entity.po.FromRohmCapacityPO;
import cn.lystudio.rohmtimeopwide_background_v11.entity.vo.FromRohmCapaVO;
import cn.lystudio.rohmtimeopwide_background_v11.mapper.FromRohmCapacityMapper;
import cn.lystudio.rohmtimeopwide_background_v11.service.FromRohmCapacityService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
@DS("master")
public class FromRohmCapacityServiceImpl extends ServiceImpl<FromRohmCapacityMapper, FromRohmCapacityPO> implements FromRohmCapacityService {
	@Resource
	private FromRohmCapacityMapper fromRohmCapacityMapper;
	@Override
	public FromRohmCapaVO getRohmCapaList(String startTimeDT, String endTimeDT,String machineNo) {
		FromRohmCapaVO fromRohmCapaVO = new FromRohmCapaVO();
		// 普通品产量
		LambdaQueryWrapper<FromRohmCapacityPO> wrapper1 = new LambdaQueryWrapper<>();
		wrapper1.between(FromRohmCapacityPO::getRecordTimeDT, startTimeDT, endTimeDT)
				.eq(FromRohmCapacityPO::getHR,0)
				.eq(FromRohmCapacityPO::getMachineNo,machineNo)
				.orderByAsc(FromRohmCapacityPO::getRecordTimeDT);
		List<FromRohmCapacityPO> commonCapaList = fromRohmCapacityMapper.selectList(wrapper1);

		// HR品产量
		LambdaQueryWrapper<FromRohmCapacityPO> wrapper2 = new LambdaQueryWrapper<>();
		wrapper2.between(FromRohmCapacityPO::getRecordTimeDT, startTimeDT, endTimeDT)
				.eq(FromRohmCapacityPO::getHR,1)
				.eq(FromRohmCapacityPO::getMachineNo,machineNo)
				.orderByAsc(FromRohmCapacityPO::getRecordTimeDT);
		List<FromRohmCapacityPO> hrCapaList = fromRohmCapacityMapper.selectList(wrapper2);
		fromRohmCapaVO.setCommonCapaList(commonCapaList);
		fromRohmCapaVO.setHrCapaList(hrCapaList);
		return fromRohmCapaVO;
	}
}
